package com.whfc.wxmp.api.safety.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.safety.dto.*;
import com.whfc.safety.param.SafetyDangerAddExtParam;
import com.whfc.safety.param.SafetyDangerCheckAddParam;
import com.whfc.safety.param.SafetyDangerControlCompleteParam;
import com.whfc.safety.param.SafetyDangerEditExtParam;
import com.whfc.wxmp.api.safety.service.WxSafetyDangerService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description 危大工程
 * @Author hw
 * @Date 2021-08-20 9:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/mp/api/safety/danger")
public class WxSafetyDangerController extends BaseController {

    @Autowired
    private WxSafetyDangerService wxSafetyDangerService;


    @GetMapping("list")
    public Result list(@CurrentWxUser WxUser user,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "state", required = false) Integer state,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "危大工程台账列表", RequestConetxtUtil.getParameters());
        PageData<SafetyDangerDTO> list = wxSafetyDangerService.list(deptId, state, pageNum, pageSize);
        return ResultUtil.success(list);
    }

    @GetMapping("ext/list")
    public Result dangerExt(@CurrentWxUser WxUser user,
                            @RequestParam("dangerId") Integer dangerId,
                            @RequestParam("type") Integer type,
                            @RequestParam("pageNum") Integer pageNum,
                            @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "查询当前进度、施工旁站、一般验收、排查记录", RequestConetxtUtil.getParameters());
        PageData<SafetyDangerExtDTO> list = wxSafetyDangerService.dangerExt(dangerId, type, pageNum, pageSize);
        return ResultUtil.success(list);
    }

    @PostMapping("ext/add")
    public Result dangerAddExt(@CurrentWxUser WxUser user,
                               @Validated @RequestBody SafetyDangerAddExtParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "新增前进度、施工旁站、一般验收、排查记录", RequestConetxtUtil.getParameters());

        wxSafetyDangerService.dangerAddExt(param,user.getPhone());
        return ResultUtil.success();
    }

    @PostMapping("ext/edit")
    public Result dangerEditExt(@CurrentWxUser WxUser user,
                                @Validated @RequestBody SafetyDangerEditExtParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "修改前进度、施工旁站、一般验收、排查记录", RequestConetxtUtil.getParameters());
        wxSafetyDangerService.dangerEditExt(param);
        return ResultUtil.success();
    }

    @PostMapping("ext/del/{extId}")
    public Result dangerExtDel(@CurrentWxUser WxUser user,
                               @RequestParam("type") Integer type,
                               @RequestParam("dangerId") Integer dangerId,
                               @PathVariable("extId") Integer extId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "删除当前进度、施工旁站、一般验收、排查记录", RequestConetxtUtil.getParameters());
        wxSafetyDangerService.dangerExtDel(dangerId, extId, type);
        return ResultUtil.success();
    }

    @GetMapping("check/num")
    public Result dangerExt(@CurrentWxUser WxUser user,
                            @RequestParam("dangerId") Integer dangerId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "问题隐患统计", RequestConetxtUtil.getParameters());
        SafetyDangerCheckNumDTO data = wxSafetyDangerService.dangerCheckNum(dangerId);
        return ResultUtil.success(data);
    }

    @GetMapping("check/list")
    public Result dangerCheckList(@CurrentWxUser WxUser user,
                                  @RequestParam("dangerId") Integer dangerId,
                                  @RequestParam("pageNum") Integer pageNum,
                                  @RequestParam("pageSize") Integer pageSize) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "问题隐患列表", RequestConetxtUtil.getParameters());
        PageData<SafetyCheckDTO> list = wxSafetyDangerService.dangerCheckList(dangerId, pageNum, pageSize);
        return ResultUtil.success(list);
    }

    @GetMapping("check/details")
    public Result dangerCheckDesc(@CurrentWxUser WxUser user,
                                  @RequestParam("checkId") Integer checkId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "问题隐患详情", RequestConetxtUtil.getParameters());
        SafetyCheckDescDTO data = wxSafetyDangerService.dangerCheckDesc(checkId);
        return ResultUtil.success(data);
    }

    @PostMapping("check/add")
    public Result dangerCheckAdd(@CurrentWxUser WxUser user,
                                 @Validated @RequestBody SafetyDangerCheckAddParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "新增问题隐患", RequestConetxtUtil.getParameters());
        wxSafetyDangerService.dangerCheckAdd(param, user.getPhone());
        return ResultUtil.success();
    }

    @GetMapping("control/list")
    public Result dangerControlList(@CurrentWxUser WxUser user,
                                    @RequestParam("dangerId") Integer dangerId) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "管控要点", RequestConetxtUtil.getParameters());
        ListData<SafetyDangerControlDTO> list = wxSafetyDangerService.dangerControlList(dangerId);
        return ResultUtil.success(list);
    }

    @PostMapping("control/complete")
    public Result dangerControlComplete(@CurrentWxUser WxUser user,
                                        @Validated @RequestBody SafetyDangerControlCompleteParam param) {
        logger.info("WXMPUA|{}|{}|{}|{}|{}",
                user.getId(), RequestConetxtUtil.getAppType(), RequestConetxtUtil.getPage(),
                "提交管控要点状态", RequestConetxtUtil.getParameters());
        wxSafetyDangerService.dangerControlComplete(param);
        return ResultUtil.success();
    }
}
